<?php
/**
 * 关键词的处理类
 */
namespace Addons\Text;


use Addons\Module;
use Addons\Text\Model\TextContent;

class Keyword extends Module {

    // 关键词界面
    public function form($rid = 0) {
        if ($rid > 0) {
            $info = (new TextContent())->where(['rid'=>$rid])->find();
            $this->content = $info;
        }
        return $this->fetch($this->template . 'form.html');
    }

    // 保存数据
    public function submit($data) {
        if($id = (new TextContent())->getFieldByRid($data['rid'],'id')){
            $data['id'] = $id;
        }
        $this->store(new TextContent(), $data, function () {
            $this->success('保存成功!', U('Module/Keyword/lists', ['mo' => 'text']));
            exit;
        });
    }

}